package cn.bouncyslime.graduationProject.nba.controller;

import cn.bouncyslime.graduationProject.nba.dto.PlayerInfoDto;
import cn.bouncyslime.graduationProject.nba.dto.TeamDto;
import cn.bouncyslime.graduationProject.nba.service.PlayerInfoService;
import cn.bouncyslime.graduationProject.nba.service.TeamService;
import cn.bouncyslime.graduationProject.nba.util.ResponseData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author 张一卓
 * @date 2020/4/3 14:27
 **/
@Controller
public class PlayerInfoController {

    private static final Logger logger = LoggerFactory.getLogger(PlayerInfoController.class);

    @Autowired
    PlayerInfoService playerInfoService;
    @Autowired
    TeamService teamService;

    @RequestMapping("toSearchPlayerInfo")
    public String toSearchPlayerInfoPage(ModelMap modelMap) {
        List<PlayerInfoDto> playerInfoDtoList = playerInfoService.listTopPlayers();
//        List<TeamDto> allTeam = teamService.listAllTeams();
        modelMap.addAttribute("topPlayerList", playerInfoDtoList);
//        modelMap.addAttribute("teamList", allTeam);
        return "playerInfo";
    }

    @RequestMapping(value = "searchPlayer", method = {RequestMethod.POST, RequestMethod.GET})
    public String searchPlayer(ModelMap modelMap, @RequestParam String name, @RequestParam String role, @RequestParam String team) {
        ResponseData responseData = playerInfoService.queryPlayer(name, role, team);
        modelMap.addAttribute(responseData);
        return "playerList";
    }

    @RequestMapping(value = "getPlayerById", method = {RequestMethod.POST, RequestMethod.GET})
    public String getPlayer(ModelMap modelMap, @RequestParam String playerId){
        ResponseData responseData = playerInfoService.getPlayerById(Integer.valueOf(playerId));
        modelMap.addAttribute(responseData);
        return "player";
    }

}
